import Studycodemodel from "../mysql_interface/studycodemodel";

export type ISR = {
    error: number
    msg: string
    enmsg: 'RuntimeError' | 'CompileError' | 'Accepted' | 'WrongAnswer'
    abbreviation: 'RE' | 'CE' | 'AC' | 'WA'
}

export default function Isstderr(data: Studycodemodel.Iuserquestioninfo = {}): ISR {
    if (data.error && data.stderr) {
        return {
            error: 2,
            msg: '运行错误',
            enmsg: 'RuntimeError',
            abbreviation: 'RE'
        }
    }
    if (data.result === false) {
        return {
            error: 1,
            msg: '答案错误',
            enmsg: 'WrongAnswer',
            abbreviation: 'WA'
        }
    }
    if (data.result === true) {
        return {
            error: 0,
            msg: '正确',
            enmsg: 'Accepted',
            abbreviation: 'AC'
        }
    }
    if (data.output?.replace(/(\s+)$/gi, "") === data.output?.replace(/(\s+)$/gi, "")) {
        return {
            error: 0,
            msg: '正确',
            enmsg: 'Accepted',
            abbreviation: 'AC'
        }
    } else {
        return {
            error: 1,
            msg: '答案错误',
            enmsg: 'WrongAnswer',
            abbreviation: 'WA'
        }
    }
}